//
//  UIButton+ZY_Button.m
//  VeiBo
//
//  Created by apple on 16/12/2.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "UIButton+ZY_Button.h"

@implementation UIButton (ZY_Button)

+ (instancetype)ZY_setImageName:(NSString *)imageName backgroundImgName:(NSString *)backgroundImgName target:(id)target action:(SEL)action
{
    UIButton *instance =[[UIButton alloc]init];
    [instance addTarget:target action:action forControlEvents:(UIControlEventTouchUpInside)];
    [instance setImage:[UIImage imageNamed:imageName] forState: UIControlStateNormal];
    [instance setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] forState: UIControlStateHighlighted];
    [instance setBackgroundImage:[UIImage imageNamed:backgroundImgName] forState:UIControlStateNormal];
    [instance setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",backgroundImgName]] forState:UIControlStateHighlighted];
    [instance sizeToFit];
    
    return instance;
}

+ (instancetype)ZY_setImageName:(NSString *)imageName title:(NSString *)title target:(id)target action:(SEL)action
{
    UIButton *instance =[[UIButton alloc]init];
    [instance addTarget:target action:action forControlEvents:(UIControlEventTouchUpInside)];
    if (imageName != nil) {
        [instance setImage:[UIImage imageNamed:imageName] forState: UIControlStateNormal];
        [instance setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] forState: UIControlStateHighlighted];
    }
    if (title != nil) {
        [instance setTitle:title forState:UIControlStateNormal];
        [instance setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [instance setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
        instance.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    
    [instance sizeToFit];
    
    return instance;
}


@end
